#pragma once

#include <string>
#include <vector>
#include <map>

#include "api/p2pms_client_interface.hpp"
#include "rtc_base/thread.h"

#include "modules/audio_device/include/audio_device.h"

namespace p2pms
{

//==================================================================================================
// 
//==================================================================================================
class DeviceManager : public IDeviceManager
{
public:
	static DeviceManager& Instance();

	bool Init(rtc::Thread* thread);
	bool StartPlayout();
	bool StopPlayout();
	bool StartRecording();
	bool StopRecording();
	rtc::scoped_refptr<webrtc::AudioDeviceModule> GetADM();

	// IDeviceManager
	ErrCode GetMediaDevList(MediaDeviceType dev_type, std::vector<MediaDevice>& devices) override;
	ErrCode SelectDevice(const MediaDevice& device) override;
	ErrCode GetSelectedDevice(MediaDeviceType dev_type, MediaDevice& device) override;

private:
	~DeviceManager();
	ErrCode GetAudioInputDevices(std::vector<MediaDevice>& devices);
	ErrCode GetAudioOutputDevices(std::vector<MediaDevice>& devices);
	ErrCode GetVideoInputDevices(std::vector<MediaDevice>& devices);

private:
	rtc::Thread* m_thread = nullptr;
	std::map<MediaDeviceType, MediaDevice> m_selected_devices; // 存储已选设备
	rtc::scoped_refptr<webrtc::AudioDeviceModule> m_adm;
};

} // namespace p2pms